package com.yryp.sign.web.service.impl;

import com.yryp.sign.entry.SignPerson;
import com.yryp.sign.utils.DateTimeUtil;
import com.yryp.sign.web.mapper.SignPersonMapper;
import com.yryp.sign.web.service.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SignServiceImpl implements SignService {

    @Autowired
    private SignPersonMapper signPersonMapper;

    @Override
    public void syncData(SignPerson signPerson) {
        if ("2".equals(signPerson.getState())){
            signPersonMapper.deleteSignPerson(signPerson.getInvitationCode());
            return;
        }
       SignPerson old = signPersonMapper.selectById(signPerson.getInvitationCode());
        if ("3".equals(signPerson.getState())){
            signPerson.setSignTime(DateTimeUtil.getFormatCurrentTime());
        }
       if (null == old){
           signPersonMapper.insertSignPerson(signPerson);
       }else {
           signPerson.setDataUpdateTime(DateTimeUtil.getFormatCurrentTime());
           signPersonMapper.updateSignPerson(signPerson);
       }
    }

    @Override
    public SignPerson selectById(String id) {
        return signPersonMapper.selectById(id);
    }

    @Override
    public List<SignPerson> selectByName(String name) {
        return signPersonMapper.selectByName(name);
    }

    @Override
    public SignPerson selectByMd5Number(String md5Number) {
        return signPersonMapper.selectByMd5Number(md5Number);
    }

    @Override
    public void updateSignPerson(SignPerson signPerson) {
        signPersonMapper.updateSignPerson(signPerson);
    }
}
